﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Runtime.Serialization;
using System.Data.Objects;

namespace GTServices.Entities
{

    public enum SearchErrorType
    {
        NoPatterns = 0,
        NoFiles,
        NoFilesWithSelectedExtensions,
    }

    public class GrepRequest : BaseEntity
    {
        [Key]
        public Guid Id { get; set; }

        public string RootPath { get; set; }
        public bool Recursive { get; set; }

        public int LinesBefore { get; set; }
        public int LinesAfter { get; set; }

        public int eErrorType { get; private set; }
        public SearchErrorType ErrorType
        {
            get { return (SearchErrorType)eErrorType; }
            set { eErrorType = (int)value; }
        }

        public DateTime Start;

        public virtual IList<FileExtension> FileExtensions { get; set; } 
        public virtual IList<FileInfo> FileInfos { get; set; }
        public virtual IList<Category> Categories { get; set; }
        public virtual IList<Pattern> Patterns { get; set; }
        public virtual IList<Language> Languages { get; set; } 

        public GrepRequest()
        {
            Id = Guid.NewGuid(); 
            this.FileInfos = new List<FileInfo>();
            this.Categories = new List<Category>();
            this.Patterns = new List<Pattern>();
            this.Languages = new List<Language>();
            this.LinesAfter = 2;
            this.LinesBefore = 2;
        }

        public override void Validate()
        {
            if (String.IsNullOrEmpty(RootPath))
            {
                throw new ArgumentException("Null or Empty Extension");
            }
        }

        public override bool Equals(object obj)
        {
            if (!(obj is GrepRequest))
            {
                return false;
            }
            return (obj as GrepRequest).Id == this.Id;
        }
        
    }
}
